#include <stm32f103.h>

#define SYSTICK_BASE				(SCS_BASE + 0x0010)
#define SYSTICK					((SYSTICK_TypeDef *)SYSTICK_BASE)

typedef struct
{
	__IO uint32_t CTRL;
	__IO uint32_t LOAD;
	__IO uint32_t VAL;
	__I  uint32_t CALIB;
} SYSTICK_TypeDef;

void delay_us(unsigned int delay)
{
	SYSTICK->LOAD = 72 * delay;
	SYSTICK->CTRL = 0x00000005;
	while(!(SYSTICK->CTRL & 0x00010000));
	SYSTICK->CTRL = 0x00000004;
}

void delay_ms(unsigned int delay)
{
	while(delay--)
	{
		delay_us(1000);
	}
}

void delay_s(unsigned int delay)
{
	while(delay--)
	{
		delay_ms(1000);
	}
}